/**
 * 定义路由： Router.[method](path, (request, response) => { })
 *    Router: 路由实例
 *    app.method(path, (request, response) => { })
 */
// 使用 multer 处理文件上传
const multer = require("multer");
const { v4: uuid } = require("uuid");
const path = require("path");
// 配置上传文件的存储位置和文件名
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, "./public/avatars");
    },
    filename: function (req, file, cb) {
        const ext = path.extname(file.originalname);
        cb(null, uuid() + ext);
    },
});
const upload = multer({ storage });

const { db } = require("../database");

const { validate, validators } = require("../validate");

// 导入加密函数
const { makePassword, checkPassword } = require("../utils");
// jwt
const { sign } = require("../jwt");
const multiAvatar = require("@multiavatar/multiavatar");

const router = require("express").Router();
const { useAuthorization}  = require("./base");
router.use(useAuthorization); //You，13小时前。用户
//新增审批
router.post('/approveInfo',

    async (req, res) => {
        const { comment, document, approver, approveTime } = req.body;
        // 插入审批信息
        const id = await db.insert('insert into approveinfo(comment, document, approver, approveTime) values (?, ?, ?, ?)', [comment, document, approver, approveTime])
             
        const approveInfo = await db.findOne`select * from approveinfo where id = ${id}`;
        res.send({
            success: true,
            message: "新增审批成功",
            object: approveInfo,
        });
    }
)
const registerRouter = (app) => app.use("/approveInfo", router);
module.exports = { registerRouter };